<?php
class Form_Category extends Zend_Form 
{
	public function __construct(Model_Category $category, Model_Category_Mapper $mapper)
	{
		parent::__construct(); 
		$this->setName('category');
		$this->setAction('/category/edit/id/' . $category->id);
		$name = new Zend_Form_Element_Text('name', array('label'=>'name'));
		$parent = new Zend_Form_Element_Select('parent_id', array('label'=>'parent'));
		$parent->addMultiOption('0', 'Корневая категория');
		foreach($mapper->getAll() as $row){
			$parent->addMultiOption($row->id, $row->name);
		} 
		$parent->setValue((int)$category->parent_id); 
		$submit = new Zend_Form_Element_Submit('submit', array('value'=>'ok'));
		$this->addElements(array($name, $parent , $submit));	
		$this->populate($category->toArray());

	}
}